package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.washe.config.WasheConfig;
import com.yanqu.road.entity.activity.washe.config.WasheSeasonConfig;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.server.gameplayer.module.activity.washe.WasheModule;
import com.yanqu.road.server.manger.activity.washe.WasheMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class WasheMallLimit extends BaseActivityMallLimit {

    public WasheMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        WasheConfig washeConfig = WasheMgr.getWasheConfig();
        if (washeConfig == null || washeConfig.getSeasonId() <= WasheConfig.SEASON_ID_TEST) {
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }

        WasheSeasonConfig seasonConfig = washeConfig.getWasheSeasonConfig();
        long now = System.currentTimeMillis();
        if (seasonConfig == null || now < seasonConfig.getBeginShowTime() || now > seasonConfig.getEndShowTime()) {
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }

        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        return SystemOpenMgr.systemOpen(player, eSystemId.WasheActivity.getValue());
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        LimitBuyResult limitBuyResult = new LimitBuyResult();
        limitBuyResult.setLimitCount(1);
        return limitBuyResult;
    }

    @Override
    protected int logicCheck() {
        boolean buyToken = player.getModule(WasheModule.class).canRechargeToken(mallInfo);
        if (!buyToken) {
            return GameErrorCode.E_MALL_LIMIT_BUY;
        }
        return 0;
    }
}
